package org.dromara.oce.domain;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.oce.constant.CommonConstantsJuLang;
import org.dromara.oce.utils.CommonConstants;
import org.dromara.oce.utils.TimeUtils;
import org.springframework.util.ObjectUtils;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

/**
 * 广告主消耗记录对象 oce_everyday_cost_hours
 *
 * @author Lion Li
 * @date 2024-12-24
 */
@Data
@EqualsAndHashCode()
@TableName("oce_everyday_cost_hours")
public class OceEverydayCostHours implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 广告主消耗记录id
     */
    @TableId(value = "advertiser_cost_id", type = IdType.AUTO)
    private Long advertiserCostId;

    /**
     * 推广链接id
     */
    private Long referralLinkId;

    /**
     * 推广链接类型：1-袋鼠；2-番茄；3-点众；4-番茄IAA；5-袋鼠IAA；6-端原生IAP；7-端原生IAA；
     */
    private Integer referralLinkType;

    /**
     * 第三方广告主id
     */
    private String thirdAdvertiserId;

    /**
     * 第三方广告主名称
     */
    private String thirdAdvertiserName;

    /**
     * 当日日期时间戳
     */
    private Long thatdayTimestamp;

    /**
     * 当日日期
     */
    private String thatdayDate;

    /**
     * 当日某时时间戳yyyy-mm-dd HH
     */
    private Long thatdayHoursTimestamp;

    /**
     * 当日某时时间
     */
    private String thatdayHoursDate;

    /**
     * 当日总收入
     */
    private BigDecimal thatdayTotalAmount = BigDecimal.ZERO;

    /**
     * 分成金额
     */
    @Deprecated
    private BigDecimal thatdayDividendAmount = BigDecimal.ZERO;

    /**
     * 当日利润金额=当日分成金额-当日消耗
     */
    private BigDecimal thatdayProfitAmount = BigDecimal.ZERO;

    /**
     * 当日总支付笔数
     */
    private Integer thatdayPaidTotalNum = 0;

    /**
     * 当日付款人数
     */
    private Integer thatdayPaidUseNum = 0;

    /**
     * 当日注册用户的总收入
     */
    private BigDecimal thatdayRegisterTotalAmount = BigDecimal.ZERO;

    /**
     * 当日注册用户的分成金额
     */
    @Deprecated
    private BigDecimal thatdayRegisterDividendAmount = BigDecimal.ZERO;

    /**
     * 当日IAA总收入
     */
    private BigDecimal iaaTotalAmount = BigDecimal.ZERO;

    /**
     * 当日IAA分成金额
     */
    private BigDecimal iaaDividendAmount = BigDecimal.ZERO;

    /**
     * 当日IAA利润金额
     */
//    @Deprecated
//    private BigDecimal iaaProfitAmount = BigDecimal.ZERO;

    /**
     * 当日注册用户的IAA总收入
     */
    private BigDecimal iaaRegisterTotalAmount = BigDecimal.ZERO;

    /**
     * 当日注册用户的IAA分成金额
     */
    private BigDecimal iaaRegisterDividendAmount = BigDecimal.ZERO;

    /**
     * 当日注册用户的利润金额
     */
    private BigDecimal thatdayRegisterProfitAmount = BigDecimal.ZERO;

    /**
     * 短剧id
     */
    private Long dramaId;

    /**
     * 短剧名称
     */
    private String dramaTitle;

    /**
     * 总消耗
     */
    private BigDecimal cost = BigDecimal.ZERO;

    /**
     * 展示数
     */
    @TableField("`show`")
    private Integer show;

    /**
     * 平均千次展现费用=总花费/展示数*1000
     */
    private BigDecimal avgShowCost;

    /**
     * 点击数
     */
    private Integer click;

    /**
     * 平均点击单价=总花费/点击数
     */
    private BigDecimal avgClickCost;

    /**
     * 点击率=点击数/展示数*100%
     */
    private BigDecimal ctr;

    /**
     * 转化数=付费数*回传率
     */
    @TableField("`convert`")
    private Integer convert = 0;

    /**
     * 转化成本
     */
    private BigDecimal convertCost;

    /**
     * 转化率=转化数/点击数*100%
     */
    private BigDecimal convertRate;

    /**
     * 激活数
     */
    private Integer active;

    /**
     * 激活成本=总消耗/激活数
     */
    private BigDecimal activeCost;

    /**
     * 激活率=激活数/点击数*100%
     */
    private BigDecimal activeRate;

    /**
     * 首次付费数
     */
    private Integer activePay;

    /**
     * 首次付费成本=消耗/付费次数
     */
    private BigDecimal activePayCost;

    /**
     * 首次付费率=首次付费数/激活数
     */
    private BigDecimal activePayRate;

    /**
     * 付费次数
     */
    private Integer gamePayCount;

    /**
     * 付费成本=消耗/付费次数
     */
    private BigDecimal gamePayCost;

    /**
     * 消耗时速
     */
    private BigDecimal costHoursSpeed;

    /**
     * 投手名称
     */
    private String createName;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 部门id
     */
    @TableField(fill = FieldFill.INSERT)
    private Long deptId;

    /**
     * 应用类型：1-抖小；3-微小；
     */
    private Integer appType;

    /**
     * 当前时段的分成金额
     */
    private BigDecimal dividendAmountHoursCurrent = BigDecimal.ZERO;

    /**
     * 当前时段+1的分成金额
     */
    private BigDecimal dividendAmountHoursOne = BigDecimal.ZERO;

    /**
     * 当前时段+2的分成金额
     */
    private BigDecimal dividendAmountHoursTwo = BigDecimal.ZERO;

    /**
     * 当前时段+3的分成金额
     */
    private BigDecimal dividendAmountHoursThree = BigDecimal.ZERO;

    /**
     * 当前时段+4的分成金额
     */
    private BigDecimal dividendAmountHoursFour = BigDecimal.ZERO;

    /**
     * 当前时段+n的分成金额
     */
    private BigDecimal dividendAmountHoursFive = BigDecimal.ZERO;

    /**
     * 回本率
     * IAP回本率 = 总分成金额 / 总消耗金额
     * IAA回本率=（总分成金额+广告总分成金额）/ 总消耗金额
     */
    private BigDecimal extRecoveryRate = BigDecimal.ZERO;

    /**
     * 客单价
     * IAP客单价 = 当日充值分成金额 / 付费人数
     * IAA客单价 = 当日广告分成 / 转化数
     */
    private BigDecimal extAvgPrice = BigDecimal.ZERO;

    /**
     * 付费成本
     * IAP付费成本 = 消耗 / 付费人数
     * IAA付费成本 = 消耗 / 激活数
     */
    private BigDecimal extPayCost = BigDecimal.ZERO;

    /**
     * 回传率
     * 回传率 = 转化数 / 当日付款人数
     */
    private BigDecimal returnRate = BigDecimal.ZERO;

    /**
     * 当日LTV
     */
    private BigDecimal attributionMicroGame0dLtv = BigDecimal.ZERO;
    /**
     * 当日广告变现ROI
     */
    private BigDecimal attributionMicroGame0dRoi = BigDecimal.ZERO;


//    //商务当日分成金额
//    private BigDecimal thatdayDividendAmountSw = BigDecimal.ZERO;
//    //商务当日注册用户的分成金额
//    private BigDecimal thatdayRegisterDividendAmountSw = BigDecimal.ZERO;
//    //商务当日IAA分成金额
//    private BigDecimal iaaDividendAmountSw = BigDecimal.ZERO;
//    //商务当日注册用户的IAA分成金额
//    private BigDecimal iaaRegisterDividendAmountSw = BigDecimal.ZERO;
//    //商务当日利润金额=商务当日分成金额-当日消耗/1.015
//    private BigDecimal thatdayProfitAmountSw = BigDecimal.ZERO;
//    //商务当日新增利润=商务当日注册用户的分成金额-当日消耗/1.015
//    private BigDecimal thatdayRegisterProfitAmountSw = BigDecimal.ZERO;


    // 按天统计需要手动计算的

    /**
     * 计算订单分成金额（袋鼠、番茄iaa，袋鼠iaa）
     */
    public BigDecimal computeDividendAmount(BigDecimal payAmount) {
        return computeDividendAmount(this.referralLinkType, this.appType, payAmount);
    }

    /**
     * 计算分成时，袋鼠iaa和iap都需要在订单金额减掉通道费之后，再*0.92 2025.03.25 飞鸿要求的
     * 计算订单分成金额（袋鼠、番茄iaa，袋鼠iaa）
     */
    public static BigDecimal computeDividendAmount(Integer referralLinkType, Integer appType, BigDecimal payAmount) {
        if (CommonConstants.REFERRAL_LINK_TYPE_SELF.intValue() == referralLinkType) {//袋鼠
            //袋鼠   微小  0.9个点，抖小0.99   利润  = 分成 - 消耗
            if (CommonConstants.REFERRAL_APP_TYPE_DOUYIN == appType) {
//                return payAmount.multiply(new BigDecimal("0.99")).multiply(new BigDecimal("0.92")).setScale(4, RoundingMode.HALF_UP);
                return payAmount.setScale(4, RoundingMode.HALF_UP);
            } else if (CommonConstants.REFERRAL_APP_TYPE_KUAISHOU.intValue() == appType) {

            } else if (CommonConstants.REFERRAL_APP_TYPE_WECHAT.intValue() == appType) {
//                return payAmount.multiply(new BigDecimal("0.9")).multiply(new BigDecimal("0.92")).setScale(4, RoundingMode.HALF_UP);
                return payAmount.setScale(4, RoundingMode.HALF_UP);
            }
        } else if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE_IAA.intValue() == referralLinkType) {
            //番茄广告收益    分成 = 充值/0.7*0.87    利润 = 分成-消耗
            return payAmount.multiply(new BigDecimal("0.87")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE.intValue() == referralLinkType) {//番茄那里会有计算方式
            // 已废弃
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DAISHU_IAA.intValue() == referralLinkType) {//袋鼠IAA，订单模式
            if (CommonConstants.REFERRAL_APP_TYPE_DOUYIN == appType) {
//                return payAmount.multiply(new BigDecimal("0.99")).multiply(new BigDecimal("0.92")).setScale(4, RoundingMode.HALF_UP);
                return payAmount.setScale(4, RoundingMode.HALF_UP);
            } else {//先默认都是抖小的
//                return payAmount.multiply(new BigDecimal("0.99")).multiply(new BigDecimal("0.92")).setScale(4, RoundingMode.HALF_UP);
                return payAmount.setScale(4, RoundingMode.HALF_UP);
            }
        }
        return BigDecimal.ZERO;
    }

    /**
     * 计算分成时，袋鼠iaa和iap都需要在订单金额减掉通道费之后，再*0.92 2025.03.25 飞鸿要求的
     * 计算番茄iaa分成时，0.78改成0.88 2025.04.08 大风要求的
     * 计算IAA分成金额（番茄iaa，袋鼠iaa）
     */
    public static BigDecimal computeIaaDividendAmount(Integer referralLinkType, Integer appType, BigDecimal payAmount) {
        if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE_IAA.intValue() == referralLinkType) {//番茄广告收益    分成 = 充值/0.7*0.88    利润 = 分成-消耗
//            return payAmount.multiply(new BigDecimal("0.88")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
            return payAmount.divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DAISHU_IAA.intValue() == referralLinkType) {//袋鼠IAA
            if (CommonConstants.REFERRAL_APP_TYPE_DOUYIN == appType) {//分成 = 当日充值*0.99/0.7
//                return payAmount.multiply(new BigDecimal("0.99")).multiply(new BigDecimal("0.92")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
                return payAmount.divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
            } else {//先默认都是抖小的
//                return payAmount.multiply(new BigDecimal("0.99")).multiply(new BigDecimal("0.92")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
                return payAmount.divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
            }
        }
        return BigDecimal.ZERO;
    }

    public static BigDecimal computeIaaDividendAmountSw(Integer referralLinkType, Integer appType, BigDecimal payAmount) {
        if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE_IAA.intValue() == referralLinkType) {//番茄广告收益    分成 = 充值/0.7*0.88    利润 = 分成-消耗
            return payAmount.multiply(new BigDecimal("0.88")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DAISHU_IAA.intValue() == referralLinkType) {//袋鼠IAA
            if (CommonConstants.REFERRAL_APP_TYPE_DOUYIN == appType) {//分成 = 当日充值*0.99/0.7
                return payAmount.multiply(new BigDecimal("0.99")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
            } else {//先默认都是抖小的
                return payAmount.multiply(new BigDecimal("0.9")).divide(new BigDecimal("0.7"), 4, RoundingMode.HALF_UP);
            }
        }
        return BigDecimal.ZERO;
    }

    /**
     * 计算当日利润(袋鼠、点众、番茄、番茄IAA、袋鼠IAA)
     */
    public void computeProfitAmount() {
        BigDecimal costTemp = this.cost.divide(new BigDecimal("1.015"), 4, RoundingMode.HALF_UP);
        if (CommonConstants.REFERRAL_LINK_TYPE_SELF == this.referralLinkType) {//袋鼠
            this.thatdayProfitAmount = this.thatdayTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterTotalAmount.subtract(this.cost);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.subtract(costTemp);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.subtract(costTemp);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DAISHU_IAA == this.referralLinkType) {//袋鼠IAA,订单收益
            this.thatdayProfitAmount = this.thatdayDividendAmount.add(this.iaaDividendAmount).subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterDividendAmount.add(this.iaaRegisterDividendAmount).subtract(this.cost);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.add(this.iaaDividendAmountSw).subtract(costTemp);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.add(this.iaaRegisterDividendAmountSw).subtract(costTemp);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE_IAA == this.referralLinkType) {//番茄IAA
            this.thatdayProfitAmount = this.thatdayDividendAmount.add(this.iaaDividendAmount).subtract(this.cost).setScale(4, RoundingMode.HALF_UP);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterDividendAmount.add(this.iaaRegisterDividendAmount).subtract(this.cost).setScale(4, RoundingMode.HALF_UP);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.add(this.iaaDividendAmountSw).subtract(costTemp).setScale(4, RoundingMode.HALF_UP);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.add(this.iaaRegisterDividendAmountSw).subtract(costTemp).setScale(4, RoundingMode.HALF_UP);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DOUYIN_ACCOUNT_IAA == this.referralLinkType) {//端原生IAA
            this.thatdayProfitAmount = this.iaaTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.iaaRegisterTotalAmount.subtract(this.cost);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_CHUAN_SHAN_JIA_IAA == this.referralLinkType) {//穿山甲IAA
            this.thatdayProfitAmount = this.iaaTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.iaaRegisterTotalAmount.subtract(this.cost);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_DIANZHONG == this.referralLinkType) {//点众
            this.thatdayProfitAmount = this.thatdayTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterTotalAmount.subtract(this.cost);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.subtract(costTemp);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.subtract(costTemp);
        } else if (CommonConstants.REFERRAL_LINK_TYPE_FANQIE == this.referralLinkType) {//番茄
            this.thatdayProfitAmount = this.thatdayTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterTotalAmount.subtract(this.cost);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.subtract(costTemp);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.subtract(costTemp);
        } else {
            this.thatdayProfitAmount = this.thatdayTotalAmount.subtract(this.cost);
            this.thatdayRegisterProfitAmount = this.thatdayRegisterTotalAmount.subtract(this.cost);

//            this.thatdayProfitAmountSw = this.thatdayDividendAmountSw.subtract(costTemp);
//            this.thatdayRegisterProfitAmountSw = this.thatdayRegisterDividendAmountSw.subtract(costTemp);
        }
    }


    /**
     * 判断链接类型是否为iaa模式
     *
     * @return
     */
    public boolean isReferralLinkTypeIsIAA() {
        if (CommonConstantsJuLang.REFERRAL_LINK_TYPE_DAISHU_IAA == this.referralLinkType || CommonConstantsJuLang.REFERRAL_LINK_TYPE_FANQIE_IAA == this.referralLinkType
            || CommonConstants.REFERRAL_LINK_TYPE_DOUYIN_ACCOUNT_IAA == this.referralLinkType || CommonConstants.REFERRAL_LINK_TYPE_CHUAN_SHAN_JIA_IAA == this.referralLinkType) {
            return true;
        }
        return false;
    }

    /**
     * 是否计算时速
     */
    public boolean isExecuteComputeHoursSpeed() {
        //消耗、展现、收入大于就计算时速
        return this.cost.doubleValue() > 0 || this.show.intValue() > 0 || this.thatdayTotalAmount.doubleValue() > 0;
    }

    // 按小时统计要计算的

    /**
     * 计算得到需要计算的字段
     */
    public void computeValue() {
        if (this.show != null && this.show > 0) {
            this.avgShowCost = NumberUtil.div(this.cost, this.show, 5, RoundingMode.HALF_UP).scaleByPowerOfTen(3);
        }
        if (this.click != null && this.click > 0) {
            this.avgClickCost = NumberUtil.div(this.cost, this.click, 2, RoundingMode.HALF_UP);
        }
        if (this.show != null && this.show > 0) {
            this.ctr = NumberUtil.div(this.click, this.show, 4, RoundingMode.HALF_UP).scaleByPowerOfTen(2);
        }
        if (this.convert != null && this.convert > 0) {
            this.convertCost = NumberUtil.div(this.cost, this.convert, 2, RoundingMode.HALF_UP);
        }
        if (this.click != null && this.click > 0) {
            this.convertRate = NumberUtil.div(this.getConvert(), this.click, 4, RoundingMode.HALF_UP).scaleByPowerOfTen(2);
        }
        if (this.active != null && this.active > 0) {
            this.setActiveCost(NumberUtil.div(this.cost, this.active, 2, RoundingMode.HALF_UP));
        }
        if (this.click != null && this.click > 0) {
            this.setActiveRate(NumberUtil.div(this.active, this.click, 4, RoundingMode.HALF_UP).scaleByPowerOfTen(2));
        }
        if (this.activePay != null && this.activePay > 0) {
            this.setActivePayCost(NumberUtil.div(this.cost, this.activePay, 4, RoundingMode.HALF_UP));
        }
        if (this.active != null && this.active > 0) {
            this.setActivePayRate(NumberUtil.div(this.activePay, this.active, 4, RoundingMode.HALF_UP).scaleByPowerOfTen(2));
        }
        if (this.gamePayCount != null && this.gamePayCount > 0) {
            this.setGamePayCost(NumberUtil.div(this.cost, this.gamePayCount, 2, RoundingMode.HALF_UP));
        }
        this.computeRateValue();
    }

    /**
     * 计算抖音端原生iaa收益
     */
    public void computeDouYinAppAmount() {
        try {
            if (CommonConstants.REFERRAL_LINK_TYPE_DOUYIN_ACCOUNT_IAA == this.referralLinkType || CommonConstants.REFERRAL_LINK_TYPE_CHUAN_SHAN_JIA_IAA == this.referralLinkType) {//端原生IAA、穿山甲IAA
                this.iaaTotalAmount = this.attributionMicroGame0dLtv;
                this.iaaRegisterTotalAmount = this.attributionMicroGame0dLtv;
            }
        } catch (Exception e) {
        }
    }

    public void computeRateValue() {
        BigDecimal costTemp = cost;
        if (NumberUtil.equals(cost, BigDecimal.ZERO)) {
            costTemp = new BigDecimal("1");
        } else {
//            costTemp = costTemp.divide(new BigDecimal("1.015"), 4, RoundingMode.HALF_UP);
        }
        BigDecimal extRecoveryRate = BigDecimal.ZERO;
        if (!isReferralLinkTypeIsIAA()) {
            extRecoveryRate = this.thatdayTotalAmount.divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
        } else {
            extRecoveryRate = (this.iaaTotalAmount.add(this.thatdayTotalAmount)).divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
        }
        this.setExtRecoveryRate(extRecoveryRate);


        BigDecimal extAvgPrice = BigDecimal.ZERO;
        if (!isReferralLinkTypeIsIAA()) {
            if (!ObjectUtils.isEmpty(thatdayPaidUseNum) && thatdayPaidUseNum > 0) {
                extAvgPrice = thatdayTotalAmount.divide(new BigDecimal(thatdayPaidUseNum), 2, RoundingMode.HALF_UP);
            }
        } else {
            if (!ObjectUtils.isEmpty(convert) && convert > 0) {
                extAvgPrice = iaaTotalAmount.divide(new BigDecimal(convert), 2, RoundingMode.HALF_UP);
            }
        }
        this.setExtAvgPrice(extAvgPrice);


        BigDecimal extPayCost = BigDecimal.ZERO;
        if (!isReferralLinkTypeIsIAA()) {
            if (!ObjectUtils.isEmpty(thatdayPaidUseNum)) {
                Integer thatdayPaidUseNum2 = thatdayPaidUseNum;
                if (thatdayPaidUseNum == 0) {
                    thatdayPaidUseNum2 = 1;
                }
                extPayCost = cost.divide(new BigDecimal(thatdayPaidUseNum2), 2, RoundingMode.HALF_UP);
            }
        } else {
            if (!ObjectUtils.isEmpty(active)) {
                Integer activeTemp = active;
                if (active == 0) {
                    activeTemp = 1;
                }
                extPayCost = cost.divide(new BigDecimal(activeTemp), 2, RoundingMode.HALF_UP);
            }
        }
        this.setExtPayCost(extPayCost);
        this.returnRate = this.thatdayPaidUseNum == 0 ? BigDecimal.ZERO : new BigDecimal(this.convert).divide(new BigDecimal(this.thatdayPaidUseNum), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);
    }


    /**
     * 计算交易属于哪个T时段
     *
     * @param registerTimestamp
     * @param payTimestamp
     * @param dividendAmount
     */
    public void hoursBlockAddAmount(long registerTimestamp, long payTimestamp, BigDecimal dividendAmount) {
        try {
            registerTimestamp = TimeUtils.getHoursTimestamp(registerTimestamp);
            payTimestamp = TimeUtils.getHoursTimestamp(payTimestamp);

            int registerHours = TimeUtils.getHours(registerTimestamp);
            int payHours = TimeUtils.getHours(payTimestamp);

            long hoursNum = (payTimestamp - registerTimestamp) / 3600;
            if (hoursNum == 0 && registerHours == payHours) {
                this.dividendAmountHoursCurrent = this.dividendAmountHoursCurrent.add(dividendAmount);
            } else if (hoursNum == 0) {
                this.dividendAmountHoursOne = this.dividendAmountHoursCurrent.add(dividendAmount);
            } else if (hoursNum == 1) {
                this.dividendAmountHoursOne = this.dividendAmountHoursOne.add(dividendAmount);
            } else if (hoursNum == 2) {
                this.dividendAmountHoursTwo = this.dividendAmountHoursTwo.add(dividendAmount);
            } else if (hoursNum == 3) {
                this.dividendAmountHoursThree = this.dividendAmountHoursThree.add(dividendAmount);
            } else if (hoursNum == 4) {
                this.dividendAmountHoursFour = this.dividendAmountHoursFour.add(dividendAmount);
            } else {
                this.dividendAmountHoursFive = this.dividendAmountHoursFive.add(dividendAmount);
            }
        } catch (Exception e) {
            System.out.println("计算时段分成金额异常");
        }
    }

}
